package zlx.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import zlx.pojo.Book;
import zlx.pojo.Page;
import zlx.service.BookService;

import javax.annotation.Resource;
import java.util.List;

@Controller
public class ManagerController {
    @Resource(name ="bookService" )
    private BookService bookService;
    //http://localhost:8080/manager/bookManager?pageNo=2
    //http://localhost:8080/Library_Shop/manager/bookManager?pageNo=2
    //图书管理页面
    @RequestMapping(value = "/manager/bookManager",method = RequestMethod.GET)
    public String BookManager(Model model,Integer pageNo){
        Page<Book> page = bookService.selectAllBook(pageNo);
        page.setUrl("/manager/bookManager");
        model.addAttribute("page",page);
        return "/pages/manager/book_manager.jsp";
    }
    //编辑图书页面
    @RequestMapping(value = "/manager/bookEdit")
    public String bookEdit(){
        return "/pages/manager/book_edit.jsp";
    }
    //添加图书
    @RequestMapping(value = "/manager/bookAdd")
    public String bookAdd(Book book){
        if (book.getId()==null) {
            bookService.addBook(book);
        }else
            bookService.updateBookById(book);
        return "redirect:/manager/bookManager";
    }
    //删除图书
    @RequestMapping(value = "/manager/delete")
    public String bookAdd(Integer id,Integer pageNo){

        return "/manager/bookManager";
    }
    //修改图书
    @RequestMapping(value = "/manager/toEditBook")
    public String toEditBook(Integer id,Model model){
        Book book = bookService.queryBookById(id);
        System.out.println(""+book);
        model.addAttribute("book",book);
        return "/pages/manager/book_edit.jsp";
    }
    //后台管理系统
    @RequestMapping(value = "/manager/manager")
    public String manager(){
        return "/pages/manager/manager.jsp";
    }
    //订单管理系统
    @RequestMapping(value = "/manager/orderManager")
    public String orderManager(){
        return "/pages/manager/order_manager.jsp";
    }
}
